//
//  NSDate+Formatter.m
//  category
//
//  Created by MAC on 2018/5/12.
//  Copyright © 2018年 MAC. All rights reserved.
//

#import "NSDate+Formatter.h"

@implementation NSDate (Formatter)

static NSCalendar *_calendar = nil;
static NSDateFormatter *_displayFormatter = nil;

+ (void)initializeStatics {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        @autoreleasepool {
            if (_calendar == nil) {
                _calendar = [NSCalendar currentCalendar];
            }
            if (_displayFormatter == nil) {
                _displayFormatter = [[NSDateFormatter alloc] init];
            }
        }
    });
}

+ (NSCalendar *)sharedCalendar {
    [self initializeStatics];
    return _calendar;
}

+ (NSDateFormatter *)sharedDateFormatter {
    [self initializeStatics];
    return _displayFormatter;
}



#pragma mark - Date Formatter

- (NSString *)ex_ymdFormat {
    return [NSDate ex_ymdFormat];
}

- (NSString *)ex_hmsFormat {
    return [NSDate ex_hmsFormat];
}

- (NSString *)ex_ymdHmsFormat {
    return [NSDate ex_ymdHmsFormat];
}

+ (NSString *)ex_ymdFormat {
    return @"yyyy-MM-dd";
}

+ (NSString *)ex_hmsFormat {
    return @"HH:mm:ss";
}

+ (NSString *)ex_ymdHmsFormat {
    return [NSString stringWithFormat:@"%@ %@", [self ex_ymdFormat], [self ex_hmsFormat]];
}
@end
